package com.example.practical_training_projects.service;

import com.example.practical_training_projects.entity.pc;
import com.example.practical_training_projects.entity.questionform;
import com.example.practical_training_projects.mapper.questionformMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;


import java.util.List;
@Service
public class questionformServicelmpl implements questionformService{
    @Autowired
    private questionformMapper mapper;

    @Override
    public List<questionform> getAllQF() {
        return mapper.getAllQF();
    }

    @Override
    public PageInfo<questionform> findqfpage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<questionform> lists=mapper.getAllQF();
        PageInfo<questionform> pageInfo=new PageInfo<>(lists);
        return pageInfo;
    }

    @Override
    public Integer insertQF(questionform qf) {
        return mapper.insertQF(qf);
    }

    @Override
    public Integer deleteQF(Integer qf) {
        return mapper.deleteQF(qf);
    }

    @Override
    public Integer updateQF(questionform qf) {
        return mapper.updateQF(qf);
    }

    @Override
    public List<questionform> getQFBYName(String q_name) {
        return mapper.getQFBYName(q_name);
    }

    @Override
    public questionform findQFuid(Integer q_uid) {
        return mapper.findQFuid(q_uid);
    }

    @Override
    public void incrementLikes(Integer q_uid) {
        questionform qf = mapper.findQFuid(q_uid); // 使用正确的 mapper 实例
        if (qf != null) {
            qf.setQ_dianzan(qf.getQ_dianzan() + 1);
            mapper.updateQF(qf); // 同样，使用正确的 mapper 实例
        }
    }

    @Override
    public List<questionform> getQuestionsByMultiCriteria(String search) {
        return mapper.getQuestionsByMultiCriteria(search);
    }



}
